<?php
/**
 * 商品类
 */
namespace App\Controller\Goods;


use Common\Model;
use Common\Controller\App\CommonController;
use Think\Gd;
use Think\PHPQRcode;

class CartController extends CommonController{

    /**
     * 购物车添加数量
     */
    public function count_update(){
        $member_id = session('member_id');
        $id = intval(I('post.id'));
        $num = intval(I('post.num'));
        $model = new Model\ProductCartModel();
        $model->where("status>0 and active_id!=3 and member_id=$member_id and id=$id")->save(['num'=>$num]);
        $count = $model->where("status>0 and active_id!=3 and member_id=$member_id")->sum('num');
        $this->ajaxReturn(['code'=>200,'count'=>$count]);
    }

    /**
     * 统计购物车数量
     */
    public function count_cart(){
        $model = new Model\ProductCartModel();
        $member_id = session('member_id');
        $count = $model->where("status>0 and active_id!=3 and member_id=$member_id")->sum('num');
        if(empty($count)){
            $count = 0;
        }
        $this->ajaxReturn(['code'=>200,'count'=>$count]);
    }
    /**
     * 加入购物车
     */
    public function add_cart(){
        $skuid = I('post.skuid');
        $buyPoductNum = I('post.buyPoductNum')?I('post.buyPoductNum'):1;
        $warehouseType = I('post.warehouseType');
        $supplierId = I('post.supplierId');
        $member_id = session('member_id');
        $shop_id = self::$shop_id;
        $model = new Model\ProductCartModel();
        //获取当前已存在于有效购物车中的数量
        $existsNum = $model->getRow($member_id,$shop_id,$skuid,$warehouseType,$supplierId);
        if(empty($existsNum)){
            $existsNum = 0;
        }
        //拿取到购物车的数量 = 已存在的 + 再次准备购买的数量
        $buyPoductNum = $existsNum + $buyPoductNum;
        $res = $model->takeProductToCart($member_id,$shop_id,$skuid,$warehouseType,$supplierId,$buyPoductNum,$existsNum);
        $this->ajaxReturn($res);
    }
    /**
     * 购物车列表
     */
    public function cart_list(){
        $merber_id = session('member_id');
        $model = new Model\ProductCartModel();
        $list = $model->cart_list($merber_id);
        $this->ajaxReturn(['code'=>200,'list'=>$list]);
    }

    /**
     * 删除购物车数据
     */
    public function delete(){
        $id = I('post.id');
        if(empty($id)){
            $this->ajaxReturn(['code'=>300,'msg'=>'购物车编号错误']);
        }
        $model = new Model\ProductCartModel();
        $res = $model->where("id=$id")->delete();
        $member_id = session('member_id');
        $count = $model->where("status>0 and active_id!=3 and member_id=$member_id")->sum('num');
        if($res){
            $this->ajaxReturn(['code'=>200,'msg'=>'删除成功','num'=>$count]);
        }else{
            $this->ajaxReturn(['code'=>300,'msg'=>'删除失败']);
        }
    }

    /**
     * 升级红人 或者 直接购买
     */
    public function upgradehongren(){
        $skuid = I('post.skuid');
        if(empty($skuid)){
            $this->ajaxReturn(['code'=>300,'msg'=>'商品编号错误']);
        }
        $model = new Model\ProductSkuModel();
        $list = $model->where("id=$skuid")->field("stock_shop,ms_price,pic,pname")->select();
        if(empty($list)){
            $this->ajaxReturn(['code'=>300,'msg'=>'此礼包不存在']);
        }
        foreach($list as $v){
            $pic = explode(',',$v['pic']);
            $v['pic'] = $pic[0];

            $v['num'] = 1;
            $lists[$v['stock_shop']][] = $v;
        }
        if(empty($lists)){
            $lists = [];
        }
        $total_money = 0;
        if($lists){
            foreach($lists as $k=>$v){
                $money = 0;
                $ms_taxation = 0;
                $model = new Model\StockShopsModel();
                $info = $model->getInfoById($k);
                $lists[$k]['title'] = $info['show_title'];
                $model = new Model\LogisticsTempConModel();
                $info1 = $model->getRow($info['logisticsid']);
                $lists[$k]['free'] = intval($info1['free']);
                foreach($v as $s){
                    $money += $s['num'] * $s['ms_price']; //当前仓库商品总金额
                    $lists[$k]['total_price'] = $money;
                    $ms_taxation += $s['ms_taxation']*$s['num'];   //当前仓库商品税费

                }
                $lists[$k]['tax_price'] = $ms_taxation;  //税费
                $lists[$k]['ms_Freight_risk'] = 0;  //运费险
                if($lists[$k]['total_price'] <=200 ){
                    $lists[$k]['ms_Freight_risk'] = 1;
                }elseif($lists[$k]['total_price'] >200  && $lists[$k]['total_price'] <= 300){
                    $lists[$k]['ms_Freight_risk'] = 2;
                }elseif($lists[$k]['total_price'] > 300){
                    $lists[$k]['ms_Freight_risk'] = 3;
                }
                $lists[$k]['free_money'] = 0; //运费
                if($money<$info1['free']){
                    $free_money = $info1['default_price'];
                    $lists[$k]['free_money'] = $free_money;
                    $lists[$k]['total_price'] += $free_money;
                    $lists[$k]['total_price'] += $lists[$k]['ms_Freight_risk'];
                }else{
                    $lists[$k]['total_price'] += $lists[$k]['ms_Freight_risk'];
                }
                $total_money +=  $lists[$k]['total_price'];
            }
            $cart_list = [];
            foreach($lists as $v){
                $cart_list[] = $v;
            }
        }
        $member_id = session('member_id');
        $addressModel = new Model\MemberAddressModel();
        $address_list = $addressModel->getlist($member_id);
        $model = new Model\TarentoModel();
        $money = $model->where("member_id=$member_id")->field('account,pay_password')->find();
        $model = new Model\OrderNoticeModel();
        $list = $model->getlist();
        $this->ajaxReturn(['code'=>200,'list'=>$cart_list,'address_list'=>$address_list,'money'=>$money['account'],'pay_password'=>$money['pay_password'],'total_money'=>$total_money,'notice_list'=>$list]);
    }
    /**
     * 购物车结算
     */
    public function cartSettlement(){
        $member_id = session('member_id');
        $model = new Model\ProductCartModel();
        $list = $model->alias('c')->join("left join haiou_product_sku as pa on pa.id=c.product_id")->where("c.status>0 and c.active_id!=3 and c.member_id=$member_id")->field("c.num,pa.pname,pa.ms_price,pa.pic,c.stock_shop,pa.id,pa.ms_taxation")->select();
        foreach($list as $v){
            $pic = explode(',',$v['pic']);
            $v['pic'] = $pic[0];
            $lists[$v['stock_shop']][] = $v;
        }
        if(empty($lists)){
            $lists = [];
        }
        $total_money = 0;

        $s_array = [];
        if($lists){
            foreach($lists as $k=>$v){
                $money = 0;
                $ms_taxation = 0;
                $model = new Model\StockShopsModel();
                $info = $model->getInfoById($k);
                $lists[$k]['title'] = $info['show_title'];
                $model = new Model\LogisticsTempConModel();
                $info1 = $model->getRow($info['logisticsid']);
                $lists[$k]['free'] = intval($info1['free']);
                foreach($v as $s){
                    $money += $s['num'] * $s['ms_price']; //当前仓库商品总金额
                    $ms_taxation += $s['ms_taxation']*$s['num'];   //当前仓库商品税费
                    $lists[$k]['total_price'] = $money;
                }
                $lists[$k]['tax_price'] = $ms_taxation;  //税费
                $lists[$k]['ms_Freight_risk'] = 0;  //运费险
                if($lists[$k]['total_price'] <=200 ){
                    $lists[$k]['ms_Freight_risk'] = 1;
                }elseif($lists[$k]['total_price'] >200  && $lists[$k]['total_price'] <= 300){
                    $lists[$k]['ms_Freight_risk'] = 2;
                }elseif($lists[$k]['total_price'] > 300){
                    $lists[$k]['ms_Freight_risk'] = 3;
                }
                $lists[$k]['free_money'] = 0; //运费
                if($money<$info1['free']){
                    if(!in_array($info['logisticsid'],$s_array)){
                        $s_array[] = $info['logisticsid'];
                        $lists[$k]['free_money'] = $info1['default_price'];

                    }else{
                        $s_array[] = $info['logisticsid'];
                    }
                    //$free_money = $info1['default_price'];
                    //$lists[$k]['free_money'] = $lists[$k]['free_money'];
                    $lists[$k]['total_price'] += $lists[$k]['free_money'];
                    $lists[$k]['total_price'] += $lists[$k]['ms_Freight_risk'];
                    $lists[$k]['total_price'] += $lists[$k]['tax_price'];

                }else{
                    $lists[$k]['total_price'] += $lists[$k]['ms_Freight_risk'];
                    $lists[$k]['total_price'] += $lists[$k]['tax_price'];
                }
                $total_money += $lists[$k]['total_price'];
            }
            $cart_list = [];
            foreach($lists as $v){
                $cart_list[] = $v;
            }
        }
        $member_id = session('member_id');
        $addressModel = new Model\MemberAddressModel();
        $address_list = $addressModel->getOne($member_id);
        $model = new Model\TarentoModel();
        $money = $model->where("member_id=$member_id")->field('account,pay_password')->find();
        $model = new Model\OrderNoticeModel();
        $list = $model->getlist();
        $this->ajaxReturn(['code'=>200,'list'=>$cart_list,'address_list'=>$address_list,'money'=>$money['account'],'pay_password'=>$money['pay_password'],'total_money'=>$total_money,'notice_list'=>$list]);
    }

    /**
     * 获取多条收货地址
     */
    public function address_list(){
        $member_id = session('member_id');
        $addressModel = new Model\MemberAddressModel();
        $address_list = $addressModel->getlist($member_id);
        $this->ajaxReturn(['code'=>200,'address_list'=>$address_list]);
    }


    /*
    * 生成详情页二维码
    */
    public function getProductEwm(){

        // 已绑定的手机号和微信号
        $member_id = session('member_id');
        $model = new Model\MemberModel();
        $res = $model->getOne($member_id);


        $skuId = I('post.skuid');
        $url = "http://webapi.52ywy.com/weixin/html/productDetail.html?shop=".$res['userid']."&skuId=".$skuId;

        //查询产品信息

        $moel = new Model\ProductSkuModel();
        $result = $moel->getRow($skuId);
        $model = new Model\OrderProductModel();
        $count = $model->where("product_id=".$result['id'])->count();
        //$p_pics = explode(',',$result['pic']);

        //产品图片
        $product_pics = $result['pic'][0];
        //产品名称
        $product_name = $result['pname'];
        //产品原价
        $product_oldPrice = $result['market_price'];
        //产品现价
        $product_Price = $result['ms_price'];
        //国家图片
        $guojiapic     = $result['guojiapic'];
        //累计销量
        $sale     = $result['sale']+$count;


        $urls = APP_PATH.'ewm/xiangqing/' . $res['userid']."-".$skuId . "_product.jpg";
        if(file_exists(mb_convert_encoding($urls , 'gbk' , 'utf-8'))){
            $product_pic = APP_PATH.'ewm/xiangqing/' . $res['userId']."-".$skuId . "_product.jpg";
        }else{
            $errorCorrectionLevel = 'L';//容错级别
            $matrixPointSize = 6;//生成图片大小
            $qrcode = new PHPQRcode();
            //生成产品二维码图片
            $qrcode::png($url,  APP_PATH.'ewm/'.$res['userid'] .'_xq.png', $errorCorrectionLevel, $matrixPointSize, 2);
            $path = APP_PATH.'ewm/'.$res['userid'] . '_xq.png';//已经生成的原始二维码图
            $bgpath = APP_PATH.'ewm/xqbg1.jpg';        //背景地址
            //         $textbg = "ewm/face_bg.png";        //文字背景
            $Image = new Gd();
            $Image->open($path);
            $Image->thumb(320, 320);
            $Image->save(APP_PATH.'ewm/'.$res['userid'].'_xq.png');

            //合成两张图片
            $targetFileDark = "522ec9db6b46b";

            $dest = imagecreatefromjpeg($bgpath);    //背景图片
            $newim = imagecreatetruecolor(103, 92);
            $back = imagecolorallocatealpha($newim, 0, 0, 0, 127);
            imagejpeg($dest, APP_PATH.'ewm/xiangqing/'.$res['userid'] ."-".$skuId."_product.jpg");
            //添加 用户信息
            $pic = imagecreatefromjpeg(APP_PATH.'ewm/xiangqing/'.$res['userid']."-".$skuId."_product.jpg");
            $red = imagecolorallocate($pic, 150, 0, 0);
            $black = imagecolorallocate($pic, 0, 0, 0);


            imagejpeg($pic, APP_PATH.'ewm/xiangqing/'.$res['userid']."-".$skuId."_product.jpg");
            imagedestroy($pic);
            imagedestroy($dest);


            //第三次组合  添加商品图片
            $images_bg = imagecreatefromjpeg(APP_PATH.'ewm/xiangqing/'.$res['userid']."-".$skuId."_product.jpg");

            //产品图片
            $imageInfos_1 = $this->downloadimagefromweixin($product_pics);
            $filenames_s = APP_PATH.'ewm/xiangqing/'.$res['userid'] ."-".$skuId."_product.jpg";
            $local_files = fopen($filenames_s, 'w');
            if (false !== $local_files) {
                if (false !== fwrite($local_files, $imageInfos_1["body"])) {
                    fclose($local_files);
                }
            }
            $product_pic_s = $filenames_s;

            $Image->open($product_pic_s);
            $Image->thumb(480, 480);
            $Image->save(APP_PATH.'ewm/xiangqing/'.$res['userid']."-".$skuId.'_product.jpg');


            $product_pic = imagecreatefromjpeg($product_pic_s);
            $newims = imagecreatetruecolor(103, 92);
            $backs = imagecolorallocatealpha($newims, 0, 0, 0, 127);
            imagefilledrectangle($product_pic, 0, 0, 126, 28, $backs);

            $src = imagecreatefrompng(APP_PATH.'ewm/'.$res['userid'].'_xq.png');    //二维码
            //imagefilledrectangle($src, 0, 0, 98, 58, $back);
            imagecopymerge($images_bg, $src, 120, 581, 0, 0, imagesx($src), imagesy($src), 100); //二维码位置

            imagealphablending($images_bg);
            imagesavealpha($images_bg, true);
            imagecopymerge($images_bg, $product_pic, 0,0, 0, 0, imagesx($product_pic), imagesy($product_pic), 100);

            $guojiapic = imagecreatefrompng($guojiapic);    //国家图片
            imagefilledrectangle($guojiapic, 0, 0, 98, 58, $back);
            imagecopymerge($images_bg, $guojiapic, 65, 491, 0, 0,19, 14, 100); //国家图片位置

            imagejpeg($images_bg, APP_PATH.'ewm/xiangqing/'.$res['userid']."-".$skuId."_product.jpg");
            imagedestroy($src);
            imagedestroy($images_bg);


            //第三次组合  添加商品名称
            $pic = imagecreatefromjpeg(APP_PATH.'ewm/xiangqing/'.$res['userid']."-".$skuId."_product.jpg");
            $red = imagecolorallocate($pic, 150, 0, 0);
            $black = imagecolorallocate($pic, 0, 0, 0);

            $hui = imagecolorallocate($pic, 140, 140, 140);


            $title = mb_substr($product_name, 0, 36);
            imagefttext($pic, 18, 0, 90, 510, $black, APP_PATH.'ewm/simfang.ttf', $title. "...");
            imagefttext($pic, 18, 0, 116, 546, $red, APP_PATH.'ewm/simfang.ttf', '￥' . $product_Price);
            imagefttext($pic, 10, 0, 208, 546, $black, APP_PATH.'ewm/simfang.ttf', '￥'.$product_oldPrice);
            imagefttext($pic, 10, 0, 276, 546, $black, 'ewm/simfang.ttf', '累计销量' . $sale);

            imagefttext($pic, 15, 0, 142, 841, $hui, APP_PATH.'ewm/simfang.ttf', '来自洋玩易全球美食');
            imagefttext($pic, 15, 0, 116, 864, $hui, APP_PATH.'ewm/simfang.ttf', '长按二维码可立即购买商品');

            imagejpeg($pic, APP_PATH.'ewm/xiangqing/' . $res['userid']."-".$skuId . "_product.jpg");
            $product_pic = APP_PATH.'ewm/xiangqing/' . $res['userid']."-".$skuId . "_product.jpg";
        }

        $res = ['code' => 200, 'msg' =>'', 'result' => ['userpath' => $product_pic]];
        $this->ajaxReturn($res);
    }







    /*
	 * 生成详情页二维码
	 */
    public function getProductEwm1(){

        // 已绑定的手机号和微信号
        $member_id = session('member_id');
        $model = new Model\MemberModel();
        $res = $model->getOne($member_id);


        $skuId = 32057;//I('post.skuid');
        $url = "http://webapi.52ywy.com/weixin/html/productDetail.html?shop=".$res['userid']."&skuId=".$skuId;

        //查询产品信息

        $moel = new Model\ProductSkuModel();
        $result = $moel->getRow($skuId);
        //$p_pics = explode(',',$result['pic']);

        //产品图片
        $product_pics = $result['pic'][0];
        //产品名称
        $product_name = $result['pname'];
        //产品原价
        $product_oldPrice = $result['market_price'];
        //产品现价
        $product_Price = $result['ms_price'];


        $urls = APP_PATH.'ewm/xiangqing/' . $res['userid']."-".$skuId . "_product.jpg";
        if(file_exists(mb_convert_encoding($urls , 'gbk' , 'utf-8'))){
            $product_pic = APP_PATH.'ewm/xiangqing/' . $res['userId']."-".$skuId . "_product.jpg";
        }else{
            $errorCorrectionLevel = 'L';//容错级别
            $matrixPointSize = 6;//生成图片大小
            $qrcode = new PHPQRcode();
            //生成产品二维码图片
            $qrcode::png($url,  APP_PATH.'ewm/'.$res['userid'] .'_xq.png', $errorCorrectionLevel, $matrixPointSize, 2);
            $path = APP_PATH.'ewm/'.$res['userid'] . '_xq.png';//已经生成的原始二维码图
            //用户头像url
            $headimgurl = $res['logo'];
            $imageInfos = $this->downloadimagefromweixin($headimgurl);
            $filenames = APP_PATH.'/ewm/face/'.$res['userid'] . "_face.jpg";
            $local_files = fopen($filenames, 'w');
            if (false !== $local_files) {
                if (false !== fwrite($local_files, $imageInfos["body"])) {
                    fclose($local_files);
                }
            }
            $paths =  $filenames;    //用户头像路径
            $bgpath = APP_PATH.'ewm/xqbg.jpg';        //背景地址
            //         $textbg = "ewm/face_bg.png";        //文字背景
            $Image = new Gd();
            $Image->open($path);
            $Image->thumb(150, 150);
            $Image->save(APP_PATH.'ewm/'.$res['userid'].'_xq.png');

            $Image->open($paths);
            $Image->thumb(50, 50);
            $Image->save(APP_PATH.'ewm/face/'.$res['userid']."_face.jpg");

            //	header("content-type:image/jpeg");
            //合成两张图片
            $targetFileDark = "522ec9db6b46b";

            $dest = imagecreatefromjpeg($bgpath);    //背景图片
            $head = imagecreatefromjpeg(APP_PATH.'ewm/face/'.$res['userid']."_face.jpg");            //头像
            //         $textbg = imagecreatefrompng($textbg);    //头像背景
            $newim = imagecreatetruecolor(103, 92);
            $back = imagecolorallocatealpha($newim, 0, 0, 0, 127);
            imagefilledrectangle($head, 0, 0, 98, 58, $back);
            imagealphablending($dest, false);
            imagesavealpha($dest, true);

            imagecopymerge($dest, $head, 364, 590, 0, 0, imagesx($head), imagesy($head), 100);   //头像位置
            //         imagecopymerge($dest, $textbg, 420, 470, 0, 0, imagesx($textbg), imagesy($textbg), 100);  //头像背景
            imagejpeg($dest, APP_PATH.'ewm/xiangqing/'.$res['userid'] ."-".$skuId."_product.jpg");
            //添加 用户信息
            $pic = imagecreatefromjpeg(APP_PATH.'ewm/xiangqing/'.$res['userid']."-".$skuId."_product.jpg");
            $red = imagecolorallocate($pic, 150, 0, 0);
            $black = imagecolorallocate($pic, 0, 0, 0);


            imagejpeg($pic, APP_PATH.'ewm/xiangqing/'.$res['userid']."-".$skuId."_product.jpg");
            imagedestroy($pic);
            imagedestroy($dest);
            imagedestroy($head);


            //第三次组合  添加商品图片
            $images_bg = imagecreatefromjpeg(APP_PATH.'ewm/xiangqing/'.$res['userid']."-".$skuId."_product.jpg");

            //产品图片
            $imageInfos_1 = $this->downloadimagefromweixin($product_pics);
            $filenames_s = APP_PATH.'ewm/xiangqing/'.$res['userid'] ."-".$skuId."_product.jpg";
            $local_files = fopen($filenames_s, 'w');
            if (false !== $local_files) {
                if (false !== fwrite($local_files, $imageInfos_1["body"])) {
                    fclose($local_files);
                }
            }
            $product_pic_s = $filenames_s;

            $Image->open($product_pic_s);
            $Image->thumb(480, 480);
            $Image->save(APP_PATH.'ewm/xiangqing/'.$res['userid']."-".$skuId.'_product.jpg');


            $product_pic = imagecreatefromjpeg($product_pic_s);
            $newims = imagecreatetruecolor(103, 92);
            $backs = imagecolorallocatealpha($newims, 0, 0, 0, 127);
            imagefilledrectangle($product_pic, 0, 0, 98, 58, $backs);

            $src = imagecreatefrompng(APP_PATH.'ewm/'.$res['userid'].'_xq.png');    //二维码
            imagefilledrectangle($src, 0, 0, 98, 58, $back);

            imagealphablending($images_bg, false);
            imagesavealpha($images_bg, true);
            imagecopymerge($images_bg, $product_pic, 0,0, 0, 0, imagesx($product_pic), imagesy($product_pic), 100);

            imagecopymerge($images_bg, $src, 13, 450, 0, 0, imagesx($src), imagesy($src), 100); //二维码位置

            imagejpeg($images_bg, APP_PATH.'ewm/xiangqing/'.$res['userid']."-".$skuId."_product.jpg");
            imagedestroy($src);
            imagedestroy($images_bg);


            //第三次组合  添加商品名称
            $pic = imagecreatefromjpeg(APP_PATH.'ewm/xiangqing/'.$res['userid']."-".$skuId."_product.jpg");
            $red = imagecolorallocate($pic, 150, 0, 0);
            $black = imagecolorallocate($pic, 0, 0, 0);

            $hui = imagecolorallocate($pic, 140, 140, 140);


            $title = mb_substr($product_name, 0, 28);
            $title1 = mb_substr($product_name, 28, 100);
            imagefttext($pic, 18, 0, 170, 493, $black, APP_PATH.'ewm/simfang.ttf', $title);
            imagefttext($pic, 18, 0, 170, 520, $black, APP_PATH.'ewm/simfang.ttf', $title1);
            //         $summary = mb_substr($product_name, 0, 20);
            //         imagefttext($pic, 15, 0, 10, 480, $black, 'ewm/simfang.ttf', $summary . "...");
            imagefttext($pic, 18, 0, 170, 557, $red, APP_PATH.'ewm/simfang.ttf', '现价：￥' . $product_Price);
            imagefttext($pic, 12, 0, 170, 579, $black, APP_PATH.'ewm/simfang.ttf', '原价：￥'.$product_oldPrice);
            // imagefttext($pic, 12, 0, 40, 410, $black, 'ewm/simfang.ttf', '￥' . $product_oldPrice);

            imagefttext($pic, 15, 0, 15, 622, $hui, APP_PATH.'ewm/simfang.ttf', '来自洋玩易');
            imagefttext($pic, 15, 0, 121, 622, $hui, APP_PATH.'ewm/simfang.ttf', '长按二维码可立即购买');

            imagejpeg($pic, APP_PATH.'ewm/xiangqing/' . $res['userid']."-".$skuId . "_product.jpg");
            $product_pic = APP_PATH.'ewm/xiangqing/' . $res['userid']."-".$skuId . "_product.jpg";
        }

        $res = ['code' => 200, 'msg' =>'', 'result' => ['userpath' => $product_pic]];
        $this->ajaxReturn($res);
    }

    //获得二维码图片
    private function downloadimagefromweixin($url){
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_HEADER,0);
        curl_setopt($ch, CURLOPT_NOBODY,0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        $package = curl_exec($ch);
        $httpinfo = curl_getinfo($ch);
        curl_close($ch);
        return array_merge(array('body'=>$package),array('header'=>$httpinfo));
    }
}